package com.ry.novel.controller;

import com.ry.novel.model.resp.Result;
import com.ry.novel.service.FileUploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 文件上传
 * @author ry
 * @since 2022-02-18 11:00
 **/
@RequestMapping("/upload")
@RestController
public class FileController {
    @Autowired
    private FileUploadService fileUploadService;

    /**
     * 上传图片
     * @param file  图片
     * @return  图片的映射地址
     */
    @PostMapping("/image")
    public Result<String> uploadImage(MultipartFile file){
        String resourceUrl = fileUploadService.uploadImage(file);

        return Result.ok(resourceUrl);
    }
}
